package com.zhfi.dataapply.schedule.writer.market;

import com.zhfi.dataapply.entity.data.po.market.ShareStructurePO;
import com.zhfi.dataapply.entity.data.vo.market.ShareStructureVO;
import com.zhfi.dataapply.mapper.market.ShareStructureMapper;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Component
public class ShareStructureWriter implements ItemWriter<ShareStructureVO> {

    @Autowired
    private ShareStructureMapper shareStructureMapper;

    @Override
    public void write(List<? extends ShareStructureVO> list) throws Exception {
        for (ShareStructureVO vo : list) {
            List<ShareStructurePO> shareStructureList = vo.getShareStructureList();
            if (!CollectionUtils.isEmpty(shareStructureList)) {
                for (ShareStructurePO po : shareStructureList) {
                    int i = shareStructureMapper.updateById(po);
                    if (i <= 0) {
                        shareStructureMapper.insert(po);
                    }
                }
            }
        }
    }
}
